﻿// ReSharper disable InconsistentNaming

using System.Collections.Generic;
using Common;
using ImageProcessing.Common;
using NUnit.Framework;

namespace ImageProcessing.Tests.Engine
{
    [TestFixture]
    public class RegionSelectTests
    {
        private readonly List<InterestPoint> _regionPoints = new List<InterestPoint>();
        private List<InterestPoint> _pointsWithInImage;
        private List<InterestPoint> _pointsOutsideImage;

        private RegionSelect _regionSelect;
        private List<InterestPoint> _unorderedList;
        private List<InterestPoint> _orderedList;

        [TestFixtureSetUp]
        public void Setup()
        {
            _unorderedList = new List<InterestPoint>
                                 {
                                     new InterestPoint(new PointInfo()){x = 8, y = 3},
                                     new InterestPoint(new PointInfo()){x = 1, y = 1},
                                     new InterestPoint(new PointInfo()){x = 5, y = 5},
                                     new InterestPoint(new PointInfo()){x = 10, y = 1}
                                 };

            _orderedList = new List<InterestPoint>
                               {
                                   new InterestPoint(new PointInfo()){x = 1, y = 1},
                                   new InterestPoint(new PointInfo()){x = 10, y = 1},
                                   new InterestPoint(new PointInfo()){x = 8, y = 3},
                                   new InterestPoint(new PointInfo()){x = 5, y = 5},
                               };

            _regionPoints.AddRange(_unorderedList);

            _pointsOutsideImage = new List<InterestPoint>
                                      {
                                          new InterestPoint(new PointInfo()){x = 1, y = 1},
                                          new InterestPoint(new PointInfo()){x = 1, y = 2},
                                          new InterestPoint(new PointInfo()){x = 11, y = 5}
                                      };

            _pointsWithInImage = new List<InterestPoint>
                                     {
                                         new InterestPoint(new PointInfo()){x = 5, y = 2},
                                         new InterestPoint(new PointInfo()){x = 2, y = 4},
                                         new InterestPoint(new PointInfo()){x = 4, y = 4}
                                     };

            _regionSelect = new RegionSelect(_regionPoints);
        }

        [Test]
        public void Ctor_UnorderedListSortedAntiClockWise_True()
        {
            var rs = new RegionSelect(_unorderedList);
            Assert.IsTrue(ListComparerHelper.EqualListValues(_orderedList, new List<InterestPoint>(rs.RegionPoints)));
        }


        [Test]
        public void GetPointsWithinRegionOfImage_AllOutsideRegion_IsEmpty()
        {
            Assert.IsEmpty(_regionSelect.GetPointsWithinRegionOfImage(_pointsOutsideImage));
        }

        [Test]
        public void GetPointsWithinRegionOfImage_AllWithinRegion_True()
        {
            Assert.IsTrue(ListComparerHelper.EqualListValues(_pointsWithInImage, _regionSelect.GetPointsWithinRegionOfImage(_pointsWithInImage)));
        }

        [Test]
        public void GetPointsWithinRegionOfImage_SomeWithinRegion_True()
        {
            var allPoints = new List<InterestPoint>();
            allPoints.AddRange(_pointsWithInImage);
            allPoints.AddRange(_pointsOutsideImage);

            Assert.IsTrue(ListComparerHelper.EqualListValues(_pointsWithInImage, _regionSelect.GetPointsWithinRegionOfImage(allPoints)));
        }


    }
}